<template>
  <el-select :value="value" placeholder="请选择" clearable @change="changeChannel">
    <!-- 遍历后台频道数据 -->
    <el-option v-for="item in channelOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
  </el-select>
</template>
<script>
export default {
  name: "my-channel",
  props: ["value"],
  data() {
    return {
      channelOptions: []
    };
  },
  created() {
    this.getChannelOptions();
  },
  methods: {
    changeChannel(channelId) {
      if (channelId === "") channelId = null;
      //   抛出数据
      this.$emit("input", channelId);
    },
    async getChannelOptions() {
      const {
        data: { data }
      } = await this.$http.get("/channels");

      this.channelOptions = data.channels;
    }
  }
};
</script>
<style scoped lang='less'>
</style>